package com.clusterswisdom.horn.api.tmall.action.alipay;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.clusterswisdom.horn.api.db.DbUtil;

public class TraderDBUtil {
	
	public static final String SQL_INSERT = "insert into billSpanstr (`channel`, `billDatestr`, `billSpanstr` , `billDate`) values (?, ?, ? ,?)";

	public static final Long addBill(String channel, String billDateStr, String billSpanStr,String billDate) throws SQLException {
		Connection conn = DbUtil.getUtil().getConnection();
		PreparedStatement statement = conn.prepareCall(SQL_INSERT);
		statement.setString(1, "M901");
		statement.setString(2, billDateStr);
		statement.setString(3, billSpanStr);
		statement.setString(4,billDate);
		statement.executeUpdate();
		statement.close();
		
		statement = conn.prepareStatement("select last_insert_id()");
		ResultSet resultSet = statement.executeQuery();
		try {
			if (resultSet.next()) {
				return resultSet.getLong(1);
				
			} else {
				return -1l;
				
			}
			 
		} finally {
			resultSet.close();
			statement.close();
			
		}
	}
}
